package com.approval.approvalapp.util.view;

import android.content.Context;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;
import com.github.mikephil.charting.utils.Utils;

import java.math.BigDecimal;

/**
 * Created by louyulin on 2019/4/26.
 */

public class MyMarkerView2 extends MarkerView {

    private TextView tvContent;

    public MyMarkerView2(Context context, int layoutResource) {
        super(context, layoutResource);

        tvContent = findViewById(R.id.tvContent);
    }

    // callbacks everytime the MarkerView is redrawn, can be used to update the
    // content (user-interface)
    @Override
    public void refreshContent(Entry e, Highlight highlight) {

        if (e instanceof CandleEntry) {

            CandleEntry ce = (CandleEntry) e;

            tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true));
        } else {
            BigDecimal b = new BigDecimal(e.getY());
            tvContent.setText(((int) e.getX() + 1) + "月: " + b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue() + "%");
        }

        super.refreshContent(e, highlight);
    }

    @Override
    public MPPointF getOffset() {
        return new MPPointF(-(getWidth() / 2), -getHeight());
    }
}

